B17 - Frog 1 with Restoration
https://atcoder.jp/contests/tessoku-book/tasks/tessoku_book_cp
提出
code: python
n = int(input())
h = list(map(int, input().split()))
dp = 0 * n
dp0 = 0
dp1 = abs(h0 - h1)
for i in range(2, n):
dpi = min(dpi-2 + abs(hi-2 - hi), dpi-1 + abs(hi-1 - hi))
ans = n-1
h.sort()
# 20,40,30,10
dp.sort()
# 30,30,20,0
for now in range(n-2, -1, -1):
if now == 0:
break
else:
if abs(hnow - hnow-1) == (dpnow - dpnow-1):
ans.append(hnow)
解答
code: python
n = int(input())
h = list(map(int, input().split()))
dp = 0 * n
dp0 = 0
dp1 = abs(h0 - h1)
for i in range(2, n):
dpi = min(dpi-2 + abs(hi-2 - hi), dpi-1 + abs(hi-1 - hi))
# print(h)
# 10, 30, 40, 20
# print(dp)
# 0, 20, 30, 30
ans = []
p = n-1
while True:
ans.append(p + 1)
if p == 0:
break
# どこから部屋 p に向かうのが最適かを求める
if dpp-1 + abs(hp-1-hp) == dpp:
p = p - 1
elif dpp-2 + abs(hp-2-hp) == dpp:
p = p - 2
ans.reverse()
ans2 = str(i) for i in ans
print(len(ans))
print(" ".join(ans2))